#include <iostream>
#include "Thread.hpp"
#include "ThreadPool.hpp"
#include "Log.hpp"
#include <unistd.h>
#include <vector>
#include <time.h>
#include <sys/types.h>

using namespace ThreadMoudle;
using namespace LogMoudule;
using namespace ThreadPoolMoudule;


using task_t = std::function<void()>;

const int N = 20;



void test1()
{
    int cnt = 5;
    while (cnt--)
    {
        LOG(LogLevel::DEBUG) << "Ciallo～(∠・ω ∠)⌒☆";
        sleep(2);
    }
}

void test2()
{
    int cnt = 5;
    while (cnt--)
    {
        LOG(LogLevel::DEBUG) << "                                 Ciallo～泥嚎⌒☆";
        sleep(2);
    }
}

void log()
{
    sleep(3);
    LOG(LogLevel::DEBUG)<<"日志已保存";
}


int main()
{
    // ENABLE_CONSOLE_LOG();
    ENABLE_FILE_LOG();

    ThreadPool<task_t> thread_pool(5);

    task_t arr[] = {test1,test2,log};

    thread_pool.InitThreadPool();
    thread_pool.Start();


    srand(time(0));
    while(true)
    {
        thread_pool.Enqueue(arr[rand()%(sizeof(arr) / sizeof(arr[0]))]);
        sleep(6);
    }

    thread_pool.Wait();




    return 0;
}
